package ar.edu.utn.frsf.tpae.a2012.g04.presentacion.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import ar.edu.utn.frsf.tpae.a2012.g04.service.CajaAhorroService;
import ar.edu.utn.frsf.tpae.a2012.g04.service.ClienteService;
import ar.edu.utn.frsf.tpae.a2012.g04.service.CuentaCorrienteService;
import ar.edu.utn.frsf.tpae.a2012.g04.service.PagoService;

public class ServiceLocator {

	private static ApplicationContext context;

	private static ApplicationContext getContext() {
		if (context == null) {
			synchronized (ServiceLocator.class) {
				if (context == null) {
					context = new ClassPathXmlApplicationContext(
							"classpath*:**/application-context-presentacion.xml");
				}
			}
		}
		return context;
	}

	public static ClienteService getClienteService() {
		return (ClienteService) getContext().getBean("clienteService");
	}
	public static CuentaCorrienteService getCuentaCorrienteService() {
		return (CuentaCorrienteService) getContext().getBean("cuentaCorrienteService");
	}

	public static CajaAhorroService getCajaAhorroServicio() {
		return (CajaAhorroService) getContext().getBean("cajaAhorroService");
	}
	
	public static PagoService getPagoService() {
		return (PagoService) getContext().getBean("pagoService");
	}
}
